import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import msigraphx.gibbsSampler.CondDistr;
import msigraphx.gibbsSampler.RandomVariableValue;
import msigraphx.gibbsSampler.VarDistr;
import msigraphx.graph.BayesianNetwork;
import msigraphx.graph.NetworkVertex;


public class FromLecturesTest3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		BayesianNetwork bayesianNetwork = new BayesianNetwork();
		NetworkVertex vertex1 = new NetworkVertex(0, "pali/palil");
		NetworkVertex vertex2 = new NetworkVertex(1, "chroniczne zapalenie oskrzeli");
		NetworkVertex vertex3 = new NetworkVertex(2, "rak pluc");
		NetworkVertex vertex4 = new NetworkVertex(3, "zmeczenie");
		NetworkVertex vertex5 = new NetworkVertex(4, "zmiany RTG");
		
		vertex1.addAllowedValue(new RandomVariableValue<String>(vertex1, "t"));
		vertex1.addAllowedValue(new RandomVariableValue<String>(vertex1, "f"));

		vertex2.addAllowedValue(new RandomVariableValue<String>(vertex2, "t"));
		vertex2.addAllowedValue(new RandomVariableValue<String>(vertex2, "f"));

		vertex3.addAllowedValue(new RandomVariableValue<String>(vertex3, "t"));
		vertex3.addAllowedValue(new RandomVariableValue<String>(vertex3, "f"));

		vertex4.addAllowedValue(new RandomVariableValue<String>(vertex4, "t"));
		vertex4.addAllowedValue(new RandomVariableValue<String>(vertex4, "f"));

		vertex5.addAllowedValue(new RandomVariableValue<String>(vertex5, "t"));
		vertex5.addAllowedValue(new RandomVariableValue<String>(vertex5, "f"));
		
		vertex2.addParent(vertex1);
		vertex3.addParent(vertex1);
		vertex4.addParent(vertex2);
		vertex4.addParent(vertex3);
		vertex5.addParent(vertex3);
		
		List<RandomVariableValue<String>> emptyDependantList = new Vector<RandomVariableValue<String>>();
		
		vertex1.setCondDistrRow(vertex1.getAllowedValue(0), 0.2f, emptyDependantList);
		vertex1.setCondDistrRow(vertex1.getAllowedValue(1), 0.8f, emptyDependantList);
		
		vertex2.setCondDistrRow(vertex2.getAllowedValue(0), 0.25f, vertex1.getAllowedValue(0));
		vertex2.setCondDistrRow(vertex2.getAllowedValue(0), 0.05f, vertex1.getAllowedValue(1));
		vertex2.setCondDistrRow(vertex2.getAllowedValue(1), 0.75f, vertex1.getAllowedValue(0));
		vertex2.setCondDistrRow(vertex2.getAllowedValue(1), 0.95f, vertex1.getAllowedValue(1));
		
		vertex3.setCondDistrRow(vertex3.getAllowedValue(0), 0.003f, vertex1.getAllowedValue(0));
		vertex3.setCondDistrRow(vertex3.getAllowedValue(0), 0.00005f, vertex1.getAllowedValue(1));
		vertex3.setCondDistrRow(vertex3.getAllowedValue(1), 0.997f, vertex1.getAllowedValue(0));
		vertex3.setCondDistrRow(vertex3.getAllowedValue(1), 0.99995f, vertex1.getAllowedValue(1));

		vertex4.setCondDistrRow(vertex4.getAllowedValue(0), 0.05f, vertex2.getAllowedValue(1), vertex3.getAllowedValue(1));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(0), 0.5f, vertex2.getAllowedValue(1), vertex3.getAllowedValue(0));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(0), 0.1f, vertex2.getAllowedValue(0), vertex3.getAllowedValue(1));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(0), 0.75f, vertex2.getAllowedValue(0), vertex3.getAllowedValue(0));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(1), 0.95f, vertex2.getAllowedValue(1), vertex3.getAllowedValue(1));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(1), 0.5f, vertex2.getAllowedValue(1), vertex3.getAllowedValue(0));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(1), 0.9f, vertex2.getAllowedValue(0), vertex3.getAllowedValue(1));
		vertex4.setCondDistrRow(vertex4.getAllowedValue(1), 0.25f, vertex2.getAllowedValue(0), vertex3.getAllowedValue(0));

		vertex5.setCondDistrRow(vertex5.getAllowedValue(0), 0.6f, vertex3.getAllowedValue(0));
		vertex5.setCondDistrRow(vertex5.getAllowedValue(0), 0.02f, vertex3.getAllowedValue(1));
		vertex5.setCondDistrRow(vertex5.getAllowedValue(1), 0.4f, vertex3.getAllowedValue(0));
		vertex5.setCondDistrRow(vertex5.getAllowedValue(1), 0.98f, vertex3.getAllowedValue(1));
		
		bayesianNetwork.addVertex(vertex1);
		bayesianNetwork.addVertex(vertex2);
		bayesianNetwork.addVertex(vertex3);
		bayesianNetwork.addVertex(vertex4);
		bayesianNetwork.addVertex(vertex5);
		
		Map<String,RandomVariableValue<String>> knownVariables = new HashMap<String,RandomVariableValue<String>>();
		knownVariables.put("vertex1", vertex1.getAllowedValue(1));
		knownVariables.put("vertex2", vertex2.getAllowedValue(1));
		String soughtVariableLabel = "vertex5";
		
		VarDistr<String> resultVarDistr = bayesianNetwork.computeVarDistrByKnownVariables(knownVariables, soughtVariableLabel);
		
		System.out.println("resultVarDistr = "+resultVarDistr);
	}

}
